//
//  commentCell.m
//  Growth
//
//  Created by  on 12-2-1.
//  Copyright (c) 2012年 MEETStudio. All rights reserved.
//

#import "commentCell.h"

#import "SDImageView+SDWebCache.h"

#import "PublicMethodEngine.h"

@implementation commentCell

@synthesize userIcon;
@synthesize name;
@synthesize delegate;

@synthesize yuanJiaoView;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)loadCellWith:(NSMutableDictionary *)dict isSubComment:(BOOL)isSubComment
{
	
	
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.tag = 1;
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.highlightedTextColor = [UIColor whiteColor];
    label.numberOfLines = 0;
    label.opaque = NO; // 选中Opaque表示视图后面的任何内容都不应该绘制
    label.backgroundColor = [UIColor clearColor];
	[label setFont:[UIFont systemFontOfSize:14]];
    
	NSString *content;
          
    content = [dict objectForKey:@"Body"];
    content = [self changeStringFommat:content];
        
    label.text = content;
    
    
    [self addSubview:label];
	
    
	CGRect cellFrame = [self frame];
	cellFrame.origin = CGPointMake(0, 0);
	
	CGRect rect = CGRectInset(cellFrame, 46, 20);
	label.frame = rect;
	[label sizeToFit];
    
    cellFrame.size.height=label.frame.size.height+35;
	[self setFrame:cellFrame];
	
	
	//好友名字
    NSString *friendName=[dict objectForKey:@"Author"];
      

	//NSString *friendName=@"smile";
	name.text=friendName;
    [name setFont:[UIFont boldSystemFontOfSize:14]];
    [name sizeToFit];
    [name setTextColor:Text_Color];
	
    //发表时间
    
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(280-115, 5, 104, 22)];
    [timeLabel setTextAlignment:UITextAlignmentRight];
   
    if (![[dict objectForKey:@"DateCreated"] isMemberOfClass:[NSNull class]]) {
        
        NSString *DateCreated = [dict objectForKey:@"DateCreated"];
        NSString *dateStr = [DateCreated substringWithRange:NSMakeRange(6, 13)];
        
       
        long long int creatTime = [dateStr longLongValue];
        creatTime = creatTime/1000;
        
        NSDate *nd = [NSDate dateWithTimeIntervalSince1970:creatTime];
              
        NSString *dateString = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:nd];
        
        timeLabel.text = dateString;
        
        
        //[timeLabel sizeToFit];
        [timeLabel setTextAlignment:UITextAlignmentRight];
        [timeLabel setFont:[UIFont systemFontOfSize:10]];
        [timeLabel setTextColor:Text_Color];
        [timeLabel setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:timeLabel];
              
        
    }
    else{
        
       timeLabel.text = @"";
    
    }
    
    [timeLabel release];
    
       
    //大圆角view
    
    yuanJiaoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 280, cellFrame.size.height)];
    
    yuanJiaoView.backgroundColor=[UIColor clearColor];
 
    [self.contentView insertSubview:yuanJiaoView atIndex:0]; 
    
    [yuanJiaoView setClipsToBounds:NO];

    [yuanJiaoView release];
    
      
}	


-(NSString *)changeStringFommat:(NSString *)str{
    
    PublicMethodEngine *methodEngine = [PublicMethodEngine sharedPublicMethodEngine];   
    
    return  [methodEngine changeStringFommat:str];
    
 
    
}


-(IBAction)toUserView:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    
    if (self.delegate!=nil) {
        [self.delegate toUserView:button ];
    }
    
    
}


@end
